<template>
  <div class="GoTop-container" @click="backtop">
    返回顶部
  </div>
</template>

<script>
export default {
  name: 'GoTop',
  methods: {
    backtop () {
      console.log(document.documentElement.scrollTop)
      let top = document.documentElement.scrollTop || document.body.scrollTop
      const timeTop = setInterval(() => {
        document.body.scrollTop = document.documentElement.scrollTop = top -= 50
        if (top <= 0) {
          clearInterval(timeTop)
        }
      }, 10)
    }
  }
}
</script>

<style scoped>
.GoTop-container {
  height: 50px;
  width: 50px;
  background-color: #047b7c;
  position: fixed;
  right: 50px;
  bottom: 50px;
  cursor: pointer;
}
</style>
